<template>
	<view class="content">
		<userTreasure class="userTreasure" :isSelect="isSelect" v-for="(item,index) in datasource" :key="index" :datasource="item"
			@selectTreasure="selectTreasure(item)"></userTreasure>
		<view class="list" v-if="datasource.length<=0">
			<noData></noData>
		</view>
	</view>
</template>

<script>
	import userTreasure from '@/components/treasure-item/index.vue'
	import noData from '@/components/noData/index.vue'
	import {
		getTreasureList
	} from '@/api/peopleHide.js'
	export default {

		components: {
			userTreasure,
			noData
		},
		data() {
			return {
				page: 1,
				datasource: [],
				isSelect: false
			}
		},
		onLoad: function(options) {
			if(options.isSelect){
			   this.isSelect = options.isSelect	
			}
			this.getTreasureList()
		},
		onReachBottom() {
			this.page++
			this.getTreasureList()
		},
		methods: {
			selectTreasure(e) {
				console.log(e)
				if (this.isSelect) {
					let pages = getCurrentPages();
					let prevPage = pages[pages.length - 2]; //上一个页面
					prevPage.setData({
						treasure:e.cart_info.productInfo.store_name,
						treasureId:e.cart_info.productInfo.id
					})
					wx.navigateBack({
						delta: 1
					})
				}
			},
			getTreasureList() {
				getTreasureList({
					page: this.page,
					limit: 20
				}).then(res => {
					let data = []
					if (this.page == 1) {
						data = res.data
					} else {
						data = this.datasource.concat(res.data)
					}
					this.datasource = data
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F4F5F6;
	}

	.content {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		padding: 20upx 32upx 0 32upx;
		box-sizing: border-box;
	}

	.list {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
	}

	.userTreasure {
		margin-right: 26upx;
		margin-bottom: 20upx;
	}

	.userTreasure:nth-of-type(2n) {
		margin-right: 0;
	}
</style>
